import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hud/hud.dart';
import 'package:top_foundation/component/window/window.dart';

import 'package:top_foundation/utils/util.dart';
import 'package:top_foundation_example/home/index.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [
    SystemUiOverlay.bottom,
    SystemUiOverlay.top,
  ]);
  // WXUtil().register();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ScreenAdapterInit(
      designSize: const Size(393, 844),
      builder: (context) {
        // ITheme.register();
        return PopScope(
          canPop: false,
          child: GetMaterialApp(
            theme: ThemeData(
              // fontFamily: 'pingfangM'，    //设置全局字体
              primarySwatch: Colors.blue,
            ),
            home: HomePage(),
            localizationsDelegates: const [
              // RefreshLocalizations.delegate,
              // GlobalMaterialLocalizations.delegate,
              // GlobalWidgetsLocalizations.delegate,
              // GlobalCupertinoLocalizations.delegate, //iOS
            ],
            // supportedLocales: const [
            //   Locale('zh', 'CN'),
            //   Locale('en', 'US'),
            // ],
            builder: (context, child) {
              child = IWindow.init(context, child);
              child = Hud.init(context, child);
              child = MediaQuery(
                  //设置文字大小不随系统设置改变
                  data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),

                  //全局设置键盘收缩
                  child: GestureDetector(
                    onTap: () {
                      FocusScopeNode focus = FocusScope.of(context);
                      if (!focus.hasPrimaryFocus &&
                          focus.focusedChild != null) {
                        FocusManager.instance.primaryFocus?.unfocus();
                      }
                    },
                    child: child,
                  ));
              return child;
            },
          ),
        );
      },
    );
  }
}
